<?php

namespace IDock\Insurance\JDAL\Response;

use IDock\Http\Response;
use IDock\Printer\NonCar\NonCarProductListPrinter;
use IDock\Printer\NonCar\NonCarProductPrinter;
use IDock\Printer\NonCar\NonCarSubCoveragePrinter;

class NonCarProductListResponse extends AllJDALResponse
{

    /*** @var NonCarProductListPrinter $printer */
    public $printer = NonCarProductListPrinter::class;

    public function printerInit(): Response
    {
        $data = $this->getBody();

        foreach ($data as $datum) {
            $nonCarProductPrinter = new NonCarProductPrinter;

            $nonCarProductPrinter->planName = $datum['planName'] ?? '';
            $nonCarProductPrinter->planCode = $datum['planCode'] ?? '';
            $nonCarProductPrinter->productCode = $datum['productLine'] ?? '';

            foreach ($datum['nonCarKindVoList'] ?? [] as  $kind) {
                $subCoverage = new NonCarSubCoveragePrinter();
                $subCoverage->subCode = $kind['kindCode'] ?? '';
                $subCoverage->subName = $kind['kindDesc'] ?? '';
                $subCoverage->amount = $kind['amountDesc'] ?? '';

                $nonCarProductPrinter->subCoverageAppend($subCoverage);
            }

            $this->printer->productListAppend($nonCarProductPrinter);
        }

        return $this;
    }
}
